// https://api.matsurihi.me/mltd/v1/events/

let nameListDom = document.createElement("div");
nameListDom.style.display = "none";

let bgUrlListDom = document.createElement("div");
bgUrlListDom.style.display = "none";

let bodyDom = document.getElementsByTagName("body")[0];
bodyDom.appendChild(nameListDom);
bodyDom.appendChild(bgUrlListDom);

let xml = new XMLHttpRequest();
xml.open("GET", "https://api.matsurihi.me/mltd/v1/events/", true);

xml.onreadystatechange = function() {
    if (xml.readyState === 4 && xml.status === 200) {
        let data = JSON.parse(xml.responseText);
        let BG_BASE_URL = "https://storage.matsurihi.me/mltd/event_bg/";

        let nameList = "";
        let bgUrlList = "";

        for (let i = 0; i < data.length; i++) {
            let bgInfo = data[i];

            let id = bgInfo["id"];
            let idStr = ""
            if (id < 10) {
                idStr = "000" + id;
            } else if (id < 100) {
                idStr = "00" + id;
            } else {
                idStr = "0" + id;
            }

            let bgName = bgInfo["name"].replaceAll("-", "_");
            nameList += idStr + "~~~MLTD背景-" + idStr + "-" + bgName + "<br>"

            let bgUrl = BG_BASE_URL + idStr + ".png";
            bgUrlList += bgUrl + "<br>";
            console.log(1)

        }
        nameListDom.innerHTML = nameList;
        bgUrlListDom.innerHTML = bgUrlList;
        console.log("end! ")
    }
}
xml.send();